#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
const int N = 150;
bool via[N][N] = {false};
char map[N][N];
int n, m,cnt=0;
int dx[] = { 1,1,1,0,-1,-1,-1,0 };
int dy[] = { -1,0,1,1,1,0,-1,-1 };
void dfs(int y, int x)
{
	via[y][x] = true;
	for (int i = 0; i < 8; i++)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx<0 || ny<0 || nx>m || ny>n)continue;
		if (via[ny][nx])continue;
		if (map[ny][nx] == 'W')
		{
			dfs(ny, nx);
		}
		else if (map[ny][nx] == '.')continue;
	}
}
int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", map[i]);
	}
	/*printf("\n");
	for (int i = 0; i < n; i++)
	{
		printf("%s", map[i]);
		printf("\n");
	}*/
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (map[i][j] == 'W' && via[i][j] == false)
			{
				cnt++;
				dfs(i, j);	
			}
		}
	}
	printf("%d",cnt);
	return 0;
}